import { useNavigator } from "./navigator";
import { toPayHander } from "../tools/handler";
import { onShow, onLoad } from "@dcloudio/uni-app";
import { useApi } from "./open";

// 跳转到支付页面 前置操作
export const usePayState = function () {
  const { store, ...toSet } = useNavigator();

  function toPayPage(orderno) {
    const payWay = store.getters["user/getUserDefaultPayway"];
    toPayHander(payWay, () => toSet.toPay(orderno), toSet.toSetting);
  }

  return { toPayPage };
};

// 支付页面
export const usePay = function () {
  const [payNormal] = useApi(payNormal);
  const payWayMapper = {
    1: "paypal",
    2: "stripe",
    3: "default",
    4: "offline",
  };

  function submit() {
    payNormal().then((res) => {
      if (res.code === 200) {
        // -> 跳转到第三方支付

        uni.showToast({
          title: "支付成功",
          icon: "success",
        });

        // -> 跳转到订单详情页面
        // uni.navigateTo({ url: `/pages/order/detail?id=${res.data.order_id}` });
      }
    });
  }

  return usePayState();
};
